Okay, so today we are having a look at one of the massive applications of C-frame, which is to do
with the camera.
Now if you have if you're not doing, if you're not watching these lectures in a, in a certain order,
and you have watched and you're watching this before, you have watched the C-frame lecture, um, it's
basically essential because we're applying what we looked at last lecture.
So make sure you have watched that lecture and you are confident with that lecture before you move on.
Okay.
So um, let's add a local script into starter player scripts here.
And we're going to learn how to actually move and control the camera.
Camera.
When the player controls most part of the most part themselves.
So before we can even think about coding anything to do with the camera, we first need to give ourselves
control of the player's camera in order to do.
In order to change some of the properties of it and stuff like that.
So, um, let's first reference the camera.
So can get you can get the player's camera in a local script by just referencing the camera in the workspace.
Dot current camera and current camera is the camera object being used by the local player?
Nice and easy.
We then want to give ourselves control of the player's camera, which we can do by writing down camera
dot camera type.
This is an enum.
Using the different types the camera can be is equal to enum, dot, camera, type, dot, and there's
a bunch of different types here.
Um, stationary cameras, following cameras, all kind of stuff.
We want a scriptable camera so that we can scripted ourselves.
Um, now, what this will mean immediately is if we go ahead and run the game just to make sure this
works, we should not be able to control the camera ourselves.
So, um, play the game so we can actually we actually being loaded in and I'm moving.
Okay.
Yes.
So, um, there is a bit of an issue with this.
So while, well, it should work, it should change our camera mode to scriptable.
But if we go over into the camera and go to camera tab, it's still at custom.
And custom is the type that the player uses themselves.
So how do we change this?
So why isn't it working basically?
Well, there are some core scripts which overrides the change we just made.
So how can we how can we get past those core scripts?
Well, we can kind of force our way past using a kind of, um, temporary ish method.
Um, so we can do this by writing down here using the changed function.
So camera changed like this.
So it changed.
Events will basically fire when any of the objects properties are changed or changed.
Connect function.
We have looked at this a bit in the past as well.
And this here?
Would it be property that now, if something has changed to the camera, we first want to check that
what was changed is the camera type property.
So if property is equal to um.
Oh no.
Sorry.
Um.
I didn't check it in my notes, but we could to make it occur less.
Yeah, because we don't want it to be fieriness every single time the position of the camera is changed,
it only wants it to be doing this on certain occasions.
So if property is equal to camera type like this here, and we also want to check that the camera type.
So camera dot camera type does not equal to enum camera type dot scriptable.
Because if we've changed it to scriptable we don't want it to change it back.
We want it to keep it as it is.
So let's say that it's changed the camera type.
And the camera type does not equal to the scriptable.
So basically it's changed the camera type um, to um back to custom.
So we want to change this by forcing us, forcing it to change it back to scriptable.
So if it's changed the camera type and a camera type is not currently scriptable, then change it back
to scriptable.
And if we play the game here, this has hopefully fixed the issue.
Yep, perfect because our camera is now forced up.
Here I am moving around.
My character has loaded.
It's here in the game.
If we take a look, if we come off the current client and go on to the server, we can see my player
is here, but I just can't control my camera at all because it is scriptable.
It is critical now, so it can only be controlled via scripts, which is what we want.
So after you've written down all that code, you can now freely move your camera using keyframe.
And now we're not really much extra need to really, really need to tell you here.
Um, anything you can use in last lesson you can use here as well.
Only thing is, when you are positioning the camera using keyframe, you don't want to be using just
keyframe.
Normally you want to be using the look at function of keyframe because cameras need to be looking at
certain areas basically.
So if we were to add in two parts, one of these is going to mean visible.
So we can if the if the camera is positioned there we can see it.
And this one I'm going to call the focus.
And this is where the camera is going to be looking at.
And let's call this make this red.
Let's move this over here.
Up there.
I'm going to find it is invisible.
Over here.
Up here.
Nice.
And make sure both feeds are anchored, actually.
Yeah.
So in this script here.
We are going to set the camera frame by saying camera C, frame like that is equal to C frame dot.
Look at the at vector is going to be the past position.
So game that workspace dot part dot position is the vector pre.
So we can use position.
And the up vector is going to be game.
The workspace dot part dot focus.
Oh sorry game the workspace dot focus dot position like that there.
And if we go ahead and play the game just to show you that this does work.
It is now positioned my part here and it's now looking at that red part there, which is really cool.
So, um, camera changing camera using the C frame is, um, absolutely vital for a lot of different
things.
One cool application I want you to try out this lesson is tween service.
Actually, you can use tween service with the camera in order to make cool cut scenes and things like
that.
So there are anything to do with the camera.
You will first need to have this bit of code.
Then you can just follow it up by using any kind of cframe lerp you can absolutely use as well.
So um, anything we looked last lesson, you can look here as well using the camera.
So do try out a lot of these applications here.
But um, this is how you would basically be able to go through with this.
Okay.
So um yeah.
Hope you enjoyed looking at camera.
I think it's really cool.
And especially try out some of the cut scenes using tween services.
That is really cool as well.
Um, a lot of game starting menus have like a cut scene playing in the background of like the map and
the camera's kind of moving around the map or a bird's eye view of the map with a slight blur on the
screen is very popular.
So that that might be something you want to have a look at as well, using a bit of guys.
But um, please try all of applications as you do often need to move.
Sorry, not move, but you do often have to code the camera in a little bit to do with your game as
well.
So this is definitely be something you have to have a look at.
So have a go smooth applications and join me in the next lecture once you're ready.